package deployment

import (
	"kubernate-server/service"

	"github.com/gin-gonic/gin"
)

/**
 * Author: 张文进
 * Description: deployments路由规则
 * Date: 2025-09-26
 */
type K8sDeploymentRouter struct {
}

func (*K8sDeploymentRouter) InitK8SDeploymentRouter(r *gin.Engine) {
	group := r.Group("/k8s/deployment")
	group.GET("/deploymentDetail/:nameSpace/:deploymentName", service.ApiGroupApp.GetDeploymentDetail)
	group.GET("/getDeploymentList/:nameSpace", service.ApiGroupApp.GetDeploymentList)
	group.DELETE("/delDeployment/:nameSpace/:deploymentName", service.ApiGroupApp.DeleteDeployment)
	group.POST("/createDeployment/:nameSpace", service.ApiGroupApp.CreateDeployment)
	group.PUT("/updateDeployment/:nameSpace/:deploymentName", service.ApiGroupApp.UpdateDeployment)
	group.PUT("/scaleDeployment/:nameSpace/:deploymentName/:replicas", service.ApiGroupApp.ScaleDeployment)
}

/*
测试案例：
1.创建Deployment http://127.0.0.1:8082/k8s/deployment/createDeployment/:nameSpace
postman测试：
  POST http://127.0.0.1:8082/k8s/deployment/createDeployment/default
请求体raw:
{
    "name": "test-nginx",
    "replicas": 2,
    "image": "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1",
    "port": 80
}
结果：
{
    "data": {
        "name": "test-nginx",
        "namespace": "default"
    },
    "message": "success"
}
*/

/*
2.获取Deployment列表 http://127.0.0.1:8082/k8s/deployment/getDeploymentList/:nameSpace
postman测试：
  GET http://127.0.0.1:8082/k8s/deployment/getDeploymentList/default
结果：
{
    "deploymentList": [
        {
            "available": 2,
            "created": "2025-09-28T14:42:50Z",
            "name": "test-nginx",
            "namespace": "default",
            "ready": 2,
            "replicas": 2
        }
    ],
    "message": "success",
    "total": 1
}
*/

/*
3. 获取Deployment详情 http://127.0.0.1:8082/k8s/deployment/deploymentDetail/:nameSpace/:deploymentName
postman测试：
GET http://127.0.0.1:8082/k8s/deployment/deploymentDetail/default/test-nginx
结果：
{
    "available": 2,
    "conditions": [
        {
            "type": "Available",
            "status": "True",
            "lastUpdateTime": "2025-09-28T14:42:51Z",
            "lastTransitionTime": "2025-09-28T14:42:51Z",
            "reason": "MinimumReplicasAvailable",
            "message": "Deployment has minimum availability."
        },
        {
            "type": "Progressing",
            "status": "True",
            "lastUpdateTime": "2025-09-28T14:42:51Z",
            "lastTransitionTime": "2025-09-28T14:42:50Z",
            "reason": "NewReplicaSetAvailable",
            "message": "ReplicaSet \"test-nginx-7c45c85d6c\" has successfully progressed."
        }
    ],
    "labels": {
        "app": "test-nginx"
    },
    "message": "success",
    "name": "test-nginx",
    "namespace": "default",
    "ready": 2,
    "replicas": 2
}
*/

/*
4.更新Deployment（镜像版本） http://127.0.0.1:8082/k8s/deployment/updateDeployment/:nameSpace/:deploymentName
postman测试：
PUT http://127.0.0.1:8082/k8s/deployment/updateDeployment/default/test-nginx
请求体raw:
{
    "image": "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v2"
}
结果：
{
    "data": {
        "image": "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v2",
        "name": "test-nginx",
        "namespace": "default"
    },
    "message": "success"
}
*/

/*
5.更新Deployment (扩缩容Deployment) 扩容到4副本 http://127.0.0.1:8082/k8s/deployment/scaleDeployment/:nameSpace/:deploymentName/:replicas
postman测试：
PUT  http://127.0.0.1:8082/k8s/deployment/scaleDeployment/default/test-nginx/4
结果：
{
    "data": {
        "name": "test-nginx",
        "namespace": "default",
        "replicas": 4
    },
    "message": "success"
}
*/

/*
6. 删除 Deployment http://127.0.0.1:8082/k8s/deployment/delDeployment/:nameSpace/:deploymentName
postman测试：
DELETE http://127.0.0.1:8082/k8s/deployment/delDeployment/default/test-nginx
结果：
{
    "data": {
        "name": "test-nginx",
        "namespace": "default"
    },
    "message": "success"
}
*/
